package com.cq.scheduer;

import com.cq.pojo.ActivityAnalysis;
import com.cq.pojo.CpmEx;
import com.cq.service.ActivityService;
import com.cq.service.CpmExService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Component
public class CpmScheduer {

    @Autowired
    private ActivityService activityService;
    @Autowired
    private CpmExService cpmExService;

    @Scheduled(cron = "1 * * * * *")
    public void taslCpm() {
        List<ActivityAnalysis> list = activityService.findActivityCpm();
        list.forEach(a -> {
            if (a.getCpm().intValue() > 70000) {
                // 存入cpm异常表
                CpmEx ex = new CpmEx();
                ex.setCpm(a.getCpm().longValue());
                ex.setCampaignId(Integer.parseInt(a.getCampaignId()));
                ex.setCampaignName(a.getCampaignName());
                ex.setCpmDate(new Date());
                ex.setCpmDiff(a.getCpm().subtract(new BigDecimal(70000)).longValue());
                ex.setStatus("0");
                cpmExService.insertCpmEx(ex);
//                System.out.println(ex.getCampaignId());
            }
        });
    }
}
